package com.nhim.cms.admin.server;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.nhim.cms.domain.CustomWidgetInstance;
import com.nhim.cms.util.CustomWidgetInstanceManager;
import com.nhim.core.AppContext;

@Service("CustomWidgetInstanceService")
public class CustomWidgetInstanceService {
	static Logger logger = Logger
	.getLogger(CustomWidgetInstanceService.class);
	public static List<CustomWidgetInstance> getByCustomWidgetId(Integer widgetId) {
		
		return CustomWidgetInstanceManager.getFromApplicationContext(
				AppContext.getApplicationContext()).getByCustomWidgetId(
				widgetId);
	}
	
	public static CustomWidgetInstance persit(CustomWidgetInstance cwInstance)
	{
		try {
			return CustomWidgetInstanceManager
			.getFromApplicationContext(AppContext.getApplicationContext()).saveOrUpdate(cwInstance);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return null;
	
	}
	public static CustomWidgetInstance findById(Integer id)
	{
		return CustomWidgetInstanceManager
		.getFromApplicationContext(AppContext.getApplicationContext()).findById(id);
	}
	
	public static Boolean remove(Integer id)
	{
		try {
			CustomWidgetInstanceManager
			.getFromApplicationContext(AppContext.getApplicationContext()).delete(id);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}


}
